package jam.network.message;

import jam.model.*;
import jam.network.*;

import java.util.*;

//
// =============================================================================
//

public class ClientRequestChannelUserList extends ClientCommand {
	protected static final String KEYWORD = "CR_USERLIST";
	private String channelName;
	
	//
	// =========================================================================
	//
	
	@Override
	public void process(ClientController controller) {
        ClientModel client = controller.getModel();

        // Create a channel if it doesn't already exist.s
        Channel channel = client.getChannel(this.channelName);
        if (channel == null) {
        	controller.send(new ServerResponse(this, false));
            return;
        }
        
        // Send the user list
        controller.send(new ServerResponse(
        		this, 
        		true,
        		new LinkedList<String>(channel.getUsers())));
	}
	
	//
    // =========================================================================
    //
    
    @Override
    protected String getKeyword() { 
        return ClientRequestChannelUserList.KEYWORD; 
    }
    
	//
	// =========================================================================
	//
	
	protected ClientRequestChannelUserList(int transactionId, Scanner args) {
		super(transactionId);
		
		// Get arguments.
		this.channelName = args.next();
	}
}
